package com.yanjiali.controller;

import com.yanjiali.feign.ArticleServiceFeign;
import com.yanjiali.model.R;
import com.yanjiali.model.req.*;
import com.yanjiali.model.resp.*;
import com.yanjiali.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Package: com.yanjiali.controller
 * @Author: yanjiali
 * @Created: 2025/4/14 20:54
 */
@RestController
@RequestMapping("/v1/articles")
@Api(tags = "文章控制器")
public class ArticleController implements ArticleServiceFeign {

    @Autowired
    private ArticleService articleService;

    @PostMapping("/upload")
    @ApiOperation("文章上传接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleUploadReq", value = "文章上传请求参数")
    })
    public R<ArticleUploadResp> articleUpload(@RequestBody ArticleUploadReq articleUploadReq) {
        return articleService.articleUpload(articleUploadReq);
    }

    @PostMapping("/getArticleList")
    @ApiOperation("文章分页条件查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ArticlePagingConditionQueryReq", value = "文章分页条件查询请求参数")
    })
    public R<ArticlePagingConditionQueryResp> articlePagingConditionQuery(@RequestBody ArticlePagingConditionQueryReq articlePagingConditionQueryReq) {
        return articleService.articlePagingConditionQuery(articlePagingConditionQueryReq);
    }

    @PostMapping("/update")
    @ApiOperation("文章修改接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleUpdateReq", value = "文章修改请求参数")
    })
    public R<ArticleUpdateResp> articleUpdate(@RequestBody ArticleUpdateReq articleUpdateReq) {
        return articleService.articleUpdate(articleUpdateReq);
    }

    @PostMapping("/getByIdArticle")
    @ApiOperation("通过id获取文章接口（需要是作者本人）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "getByIdArticleReq", value = "通过id获取文章的请求参数")
    })
    public R<GetByIdArticleResp> getByIdArticle(@RequestBody GetByIdArticleReq getByIdArticleReq) {
        return articleService.getByIdArticle(getByIdArticleReq);
    }

    @PostMapping("/delete")
    @ApiOperation("文章删除接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleDeleteRep", value = "文章删除请求参数")
    })
    public R<ArticleDeleteResp> articleDelete(@RequestBody ArticleDeleteRep articleDeleteRep) {
        return articleService.articleDelete(articleDeleteRep);
    }

    @PostMapping("/liked")
    @ApiOperation("文章点赞接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "likeArticleReq", value = "文章点赞请求参数")
    })
    public R<LikeArticleResp> likeArticle(@RequestBody LikeArticleReq likeArticleReq) {
        return articleService.likeArticle(likeArticleReq);
    }

    @Override
    public R<GetByIdArticleNoNeedAuthorResp> getByIdArticleNoNeedAuthor(@RequestParam("id") Long articleId) {
        return articleService.getByIdArticleNoNeedAuthor(articleId);
    }

    @Override
    public R<UpdateArticleCollectNumResp> updateArticleCollectNum(UpdateArticleCollectNumReq updateArticleCollectNumReq) {
        return articleService.updateArticleCollectNum(updateArticleCollectNumReq);
    }
}
